#
# Copyright (C) 2000-2023 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
# 
# This file is used as the template to create the
# Makefile for the Solaris specific installation.
#
#  15 November 2001 -- Kern Sibbald
#
#  for Bacula release @VERSION@ (@DATE@) -- @DISTNAME@
#

VPATH = @srcdir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
SED = /usr/bin/sed

nothing:

install: install-autostart

install-autostart: install-autostart-fd install-autostart-sd install-autostart-dir

	
install-autostart-fd:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-fd /etc/rc.bacula-fd
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-fd /etc/rc.conf; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.conf already patched"; \
	else \
	    rm -f /etc/rc.conf.$$today; \
	    cp -p /etc/rc.conf /etc/rc.conf.$$today; \
	    ( echo "Start the Bacula File daemon. Do not remove the 'TAG_BACULA_FD' text"; \
	      echo "if [ -x /etc/rc.bacula-fd ]; then	  # TAG_BACULA_FD"; \
	      echo "	    /etc/rc.bacula-fd start	  # TAG_BACULA_FD"; \
	      echo "fi					  # TAG_BACULA_FD"; \
	    ) >> /etc/rc.conf; \
	    echo ""; \
	fi


install-autostart-sd:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-sd /etc/rc.bacula-sd
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-sd /etc/rc.conf; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.conf already patched"; \
	else \
	    rm -f /etc/rc.conf.$$today; \
	    cp -p /etc/rc.conf /etc/rc.conf.$$today; \
	    ( echo "Start the Bacula Storage daemon. Do not remove the 'TAG_BACULA_SD' text"; \
	      echo "if [ -x /etc/rc.bacula-sd ]; then	  # TAG_BACULA_SD"; \
	      echo "	    /etc/rc.bacula-sd start	  # TAG_BACULA_SD"; \
	      echo "fi					  # TAG_BACULA_SD"; \
	    ) >> /etc/rc.conf; \
	    echo ""; \
	fi

install-autostart-dir:
	@echo "FreeBSD platform installation"
	$(INSTALL_PROGRAM) -m 744 bacula-dir /etc/rc.bacula-dir
	@-today="`date +%Y%m%d%H%M`"; \
	grep -q /etc/rc.bacula-dir /etc/rc.conf; \
	if [ $$? -eq 0 ]; then \
	    echo "/etc/rc.conf already patched"; \
	else \
	    rm -f /etc/rc.conf.$$today; \
	    cp -p /etc/rc.conf /etc/rc.conf.$$today; \
	    ( echo "Start the Bacula Director. Do not remove the 'TAG_BACULA_DIR' text"; \
	      echo "if [ -x /etc/rc.bacula-dir ]; then	  # TAG_BACULA_DIR"; \
	      echo "	    /etc/rc.bacula-dir start	  # TAG_BACULA_DIR"; \
	      echo "fi					  # TAG_BACULA_DIR"; \
	    ) >> /etc/rc.conf; \
	    echo ""; \
	fi


uninstall: uninstall-autostart

uninstall-autostart: uninstall-autostart-fd uninstall-autostart-sd uninstall-autostart-dir

uninstall-autostart-fd:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-fd
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.conf ; do \
	    grep -q '# TAG_BACULA_FD' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_FD/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done


uninstall-autostart-sd:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-sd
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.conf ; do \
	    grep -q '# TAG_BACULA_SD' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_SD/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done

uninstall-autostart-dir:
	@echo "FreeBSD platform uninstall"
	rm -f /etc/rc.bacula-dir
	@-today="`date +%Y%m%d%H%M`"; \
	for f in /etc/rc.conf ; do \
	    grep -q '# TAG_BACULA_DIR' $$f; \
	    if [ $$? -eq 0 ]; then \
		    echo "removing Bacula lines from $$f"; \
		    rm -f $$f.$$today; \
		    cp -p $$f $$f.$$today; \
		    $(SED) -e '/TAG_BACULA_DIR/d;' \
			    < $$f.$$today > $$f; \
		    chmod 644 $$f; \
	    fi; \
	done

clean:
	@rm -f 1 2 3

distclean: clean
	@rm -f bacula-sd bacula-fd bacula-dir
	@rm -f Makefile bacula-*.spec

devclean: clean
	@rm -f bacula-sd bacula-fd bacula-dir
	@rm -f Makefile bacula-*.spec
